package handler

import (
	"gitee.com/lanshiren/miniprogram/app/model"
	"gitee.com/lanshiren/miniprogram/app/service"
	"github.com/gin-gonic/gin"
)

// HandleMonitorMysqlQPS ...
func HandleMonitorMysqlQPS(c *gin.Context) {
	indicators := &model.Indicators{}
	token := c.Request.Header.Get("token")
	userData, err := service.TryGetUserSession("session-" + token)
	if err != nil {
		c.JSON(401, gin.H{
			"errMsg": "你的登录已过期, 请重新登录",
		})
		return
	}
	indicators.Points = append(indicators.Points, &model.Point{X: "18:00", Y: 234.5})
	indicators.Points = append(indicators.Points, &model.Point{X: "18:00", Y: 214.5})
	c.JSON(200, gin.H{
		"result": userData,
	})
}

// HandleQueryMySQLGlobalStatus ...
func HandleQueryMySQLGlobalStatus(c *gin.Context) {
	status, err := model.GetGlobalStatus()
	if err != nil {
		c.JSON(500, gin.Error{
			Err:  err,
			Meta: "query status err",
		})
		return
	}
	c.JSON(200, gin.H{
		"result": status,
	})
}
